home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group02b.txt / 000045_icon-group-sender_Mon Sep 23 19:48:10 2002.msg < prev    next >
Internet Message Format  |  2003-01-02  |  13KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id g8O2lAw02390
  4.     for icon-group-addresses; Mon, 23 Sep 2002 19:47:10 -0700 (MST)
  5. Message-Id: <200209240247.g8O2lAw02390@baskerville.CS.Arizona.EDU>
  6. Date: Fri, 20 Sep 2002 09:07:52 -0400
  7. From: "Steve Graham" <Steve_Graham@labcorp.com>
  8. To: <icon-group@cs.arizona.edu>
  9. Subject: Moving from Procedural to Object-Oriented (Was Re: Icon Wish
  10.     List)
  11. Content-Disposition: inline
  12. X-MIME-Autoconverted: from quoted-printable to 8bit by baskerville.CS.Arizona.EDU id g8KD8Ww18598
  13. Errors-To: icon-group-errors@cs.arizona.edu
  14. Status: RO
  15.  
  16. Andrew's post rings close to home, as my division is considering a move from a procedural language to an object-oriented one.  Accepting that on the one hand a LARGE system may benefit from the benefits of the object-oriented approach, while not forgetting that fads occur in all walks of life, including programming, I would appreciate if anyone in this group has seen the benefits vs the costs of moving from procedural to OO.  Maybe also the "be sure to avoid" things.  For my part, I see the advantage of hiding data and reusing code, but this can be done with structured code and well-crafted libraries.
  17.  
  18. TIA, Steve
  19.  
  20. ===
  21.  
  22. >>> "Andrew Hamm" <ahamm@mail.com> 09/18/02 09:57PM >>>
  23. Frank J. Lhota wrote:
  24. > Looking over the last several versions of Icon, the last several
  25. > versions did little more than adding a few functions and fix a few
  26. > bugs. It has been a while since there have been major enhancements to
  27. > the Icon language. This type of stagnation harms Icon's long term
  28. > prospects. It is time to consider some major upgrades to Icon.
  29. >
  30.  
  31. I've been watching this debate with interest (and am heartened by the
  32. increase in traffic above zero messages a month...) so here's my $0.04(AU)
  33. [current exchange rate is $1.00AU = $0.54US]
  34.  
  35. > 1) Object-Oriented Programming
  36.  
  37. Yes, Idol is very interesting, but I haven't used it in any project, just
  38. dabbled. I have used Icon for a few large tools; 3 of them are an essential
  39. part of the software development production system in my company.
  40.  
  41. The simplest one is a pre-processor in the style of cpp, which we can use
  42. with our 4GL (sql-based) source code. This is a relatively simple process,
  43. and objects could have been convenient to store things like the defines and
  44. the stack of the pre-processor blocks, however lack of OO did not cause any
  45. difficulty.
  46.  
  47. The second major tool is a 4GL code generator. It reads form specification
  48. files, accesses the database for table schema, and generates 4GL. Given the
  49. large number of source instructions representing screen objects and business
  50. rule actions, OO would have been very useful indeed and I did find myself
  51. wishing for classes *with methods* to get around my regular confusion as I
  52. got deep into nasty expressions which could only exploit . and [ ]
  53. operators. Not a few bugs were caused by mistakes with access to deep object
  54. members and performing work on them.
  55.  
  56. The 3rd major tool is a source code merger, which reads a bunch of
  57. instructions to insert, replace or delete code blocks in the generated 4GL
  58. (this allows our programmers to maintain regenerable forms and yet perform
  59. powerful modifications to the generated code, to suit the exact business
  60. needs). This tool exploits the amazing power of coroutines amongst other
  61. things, and I managed to achieve a remarkable O(N) processing time. It's
  62. remarkable because I wrote it to replace a 3rd-party tool which slowed
  63. quadratically vs code size. This process had middling need for OO but once
  64. again exploited the magic of Icon to achieve its task.
  65.  
  66. It's when projects achieve a critical mass that OO becomes a benefit. Any
  67. educational sample of OO fails to prove the need for OO IMHO. I still desire
  68. OO in Icon and forsee no costs beyond the implementation effort. I really
  69. can't see OO degrading Icon; with proper design it should fit in very nicely
  70. and elegantly. Apart from the corruption caused by it's pre-processing
  71. nature, Idol does show what is possible. With integrated support, the rough
  72. edges of Idol could be cleaned up.
  73.  
  74. It's interesting to think about the style of the syntax to use. Given that
  75. OO is only really useful for large projects, I would lean towards the "one
  76. file, one class" approach, which means that the classes could look like
  77. this:
  78.  
  79. <file foo.icl>   # just a suggestion
  80.  
  81. class Foo [ : superclass ... ]
  82.  
  83. define var, var, var ...
  84.  
  85. static classvar, classvar ...
  86.  
  87. constructor Foo( arg ... )
  88.     ....
  89. end
  90.  
  91. destructor ~Foo( )
  92.    # typical destructor stuff
  93. end
  94.  
  95. method instanceMethod( arg ... )
  96.     ...
  97. end
  98.  
  99. static method classMethod( args )
  100.     ...
  101. end
  102.  
  103. </file>
  104.  
  105. NOTE: use of "constructor", "destructor" and "method" keywords does not
  106. denote a preference.
  107.  
  108. Since Icon is completely free with variable types and call arguments, it
  109. follows that class members should not be typed, and overloaded methods do
  110. not make sense either - one name, one method. A class constructor is
  111. obviously needed, and presumably a class destructor too; for the usual
  112. application-level cleanups. Due to the nature of Icon garbage collection,
  113. the destructor would not be called at any predictable time, but then, people
  114. comfortably live with that in Java.
  115.  
  116. There's probably scope for operator overloading. Icon has a decent set of
  117. operators, and some tasks benefit from operator overloading - however,
  118. people do tend to get very silly trying to squeeze as much as possible into
  119. that mould ;)
  120.  
  121. What about member privacy? With the 1 file, 1 class model, it does become
  122. possible to add a "private" keyword for class methods, members and statics.
  123. If marked as private, the member is not visible outside the file. However,
  124. that does not fit at all with the dynamic typing of Icon. How do you know
  125. the type of a particular variable at any one time? You don't, so you can't
  126. block access to specific fields, unless some sort of runtime check was added
  127. to provide the illusion of privacy. Perhaps that's acceptable... If the
  128. runtime check was provided, then presumably protected member access could
  129. also be fitted. Personally I wouldn't fuss deeply about this. The Perlish
  130. idea of the "gentleperson's agreement" works for me.
  131.  
  132. Should member variables be accessible with the usual . notation? Or should
  133. objects *only* allow either readonly access to variables, with all
  134. assignments applied only in the class source file? Presumably, identifiers
  135. would be looked up thru the local declarations (and method args) then class
  136. variables, then finally globals. So it could be reasonable to say that
  137. Obj.varname is simply not assignable. Very easy. However, that would make
  138. even classes suspicious of themself:
  139.  
  140. class Foo;
  141.  
  142. define Bar;
  143.  
  144. method Baz( )
  145.     local other
  146.  
  147.     other := expression-yielding-Foo-object
  148.     other.Bar := 1    # ERROR!!!!! dang
  149.     other.setBar(1)  # works, but ugly
  150. end
  151.  
  152. Hence, I would keep away from that and invoke the Gentlecodesters agreement
  153. again...
  154.  
  155. With the current Icon runtime, the interpretation of obj.member would
  156. actually need to resolve to an internal object just like the pending array
  157. (or is it string?) assignments (sorry, my implementation book is at home and
  158. it's been 5 years since I last read it anyway). Since obj.field (and indeed
  159. obj[index]) could be variously interpreted as
  160.  
  161.     rec.field, or
  162.     class.field, or
  163.     class.static, or
  164.     class.method
  165.  
  166. depending in the dynamic type of obj, the . operator in the runtime would
  167. need extending so that if the left arg is an object, the field is looked up
  168. via the class. If the field is found as a member variable, then it probably
  169. could yield an assignable item just like rec.field, but if the field is
  170. found to be a method, then it should yield a new variant on the proc - a
  171. special block which also records the sender. In theory, it's entirely
  172. possible to pass this thing around before using it:
  173.  
  174.     mc := obj.method
  175.     foo(mc)
  176.     ....
  177. procedure foo(mc)
  178.     x := mc(arg1, arg2)
  179.  
  180. Simply because obj.method needs to have ( ) stuffed on the end before the
  181. actual call is applied. In normal practice of course, that is what would
  182. usually happen:
  183.  
  184.     val := obj.method(arg1, arg2)
  185.  
  186. but the internal implentation is simple and interesting because of it.
  187.  
  188. What else? Inheritance? OK...
  189.  
  190. Sure, multiple inheritance. Circular like Idol? Why not! Very interesting
  191. idea and I don't see why the compiler needs to drown in a sea of infinite
  192. recursion if decent programmers work on it ;-) What about if two supers have
  193. the same super, leading to a diamond structure?
  194.  
  195. class A
  196. class B : A
  197. class C : A
  198. class D : B C
  199.  
  200. What did Idol do? Merge? I don't remember. But Idol is probably a good
  201. guide. How's this for an alternative: Since OO is best for large projects,
  202. the Eiffel concept of "redefine" and "rename" are very appealing. Not only
  203. do these two clauses eliminate most of the anti-multiple inheritance
  204. arguments, it also solves a less talked-about problem, where a parent class
  205. might be extended by adding a new method or member, which subsequently
  206. conflicts silently with a subclass member of the same name. There is
  207. responsibility in this direction also...
  208.  
  209. The redefine and rename clauses eliminate the need for messy syntax which is
  210. needed to access overridden parent members. If they are overridden they can
  211. be made available through a different name so there is no need for nonsense
  212. like super::method( ... ).
  213.  
  214. With the rename and redefine clauses, you are expected to know and declare
  215. redefinitions. In large projects, that's a very powerful safety feature. How
  216. could this work in Objective Icon? The compiler will collect a class
  217. definition. An optional list of parent classes might be found, with optional
  218. redefine or rename clauses, along with member variables and methods. The
  219. compiler would collect all these items in good faith, and build the
  220. intermediate code as it does now, assuming that the linker and runtime will
  221. make more sense of it all.
  222.  
  223. The linker would then take on a greater role. All the class definitions need
  224. to be banged together; insert Tab A into Slot B and so on. At this point,
  225. the inheritance trees (graphs) will be constructed. I would propose that
  226. each class definition will have a private member list built, so that the
  227. runtime system does not need to travel the tree each time a member is
  228. accessed. A simple lookup of the member in the objects class will be
  229. sufficient to find it's offset within the object and it's type etc.
  230.  
  231. Back to the class traversal: For each class, visit all the parents looking
  232. for extra members and methods to attach to the class. Any conflicts which
  233. are in violation of the rename and redefine clauses can be found at this
  234. time. Therefore the class tree could be shown to be correct by the linker.
  235. By this time, everything is resolved, the final .icx is written and we're
  236. ready for the real fun to begin.
  237.  
  238. Is that enough? I've proposed something very simple, requiring only a few
  239. new internal block types to represent the classes, the objects, and the
  240. mutated proc blocks (sender.method). I've relied upon a Gentle-programmers
  241. agreement for all the usual fuss about protection, encapsulation etc.
  242. Runtime traversals to find methods can be avoided.
  243.  
  244. What about abstract classes and abstract methods? What about them? I suppose
  245. they are possible; in fact, a redefine clause without a corresponding method
  246. definition will implicitly be an abstract method. Is this any use? I would
  247. guess that an abstract method would merely be a null member in the class
  248. lookup table. Icon currently supports this (and provides a runtime error) if
  249. you attempt a call to a non-existent method. This is probably a very
  250. appropriate response for OO too.
  251.  
  252. > 2) Better Interfacing to External Programs
  253. >
  254. >[SNIP]
  255. >
  256. > Nevertheless, other languages provide ways of calling external
  257. > functions and handling external memory. Why can't Icon have these
  258. > abilities?
  259. >
  260.  
  261. Why not indeed? Perl's XS facility does a very good job. Of course, the C
  262. code must comply. Perl does offer a usable malloc and free which means it's
  263. quite easy to link in 3rd party libraries which may not assume they'll be
  264. linked into Perl. Icon/XS will need the same respect for 3rd-party
  265. libraries. The XS framework generator is a very useful tool for Perl, and
  266. points to the need for something similar with Icon.
  267.  
  268. > 3) Unicode Support
  269. >
  270.  
  271. Don't care ;-) I guess we should all get into the 21st century sooner or
  272. later...
  273.  
  274. > 4) Icon as a Scripting Language
  275. >
  276.  
  277. Interesting idea. In principle, some simple hack can already be done using
  278. hash-bang lines and possibly a bit of disguised shell-code. Isn't there an
  279. icont argument which asks for automatic execution of the resulting object?
  280. If there isn't it can surely be added.
  281.  
  282. To do this "properly" on UNIX, the compiler could probably write to a tmp
  283. file (not linked into a directory) and then hand the open file handles off
  284. to a cooperating iconx which can slurp up the icode from the tmp file
  285. handles and then close them, resulting in their deallocation. This is a very
  286. simple improvement to the compiler and runner, and I wouldn't really class
  287. this as an extension to Icon, because it's more mechanical than anything
  288. else.
  289.  
  290.  
  291.  
  292.  
  293.